package hw1106066.lesson1;

import java.util.Timer;
import java.util.TimerTask;

public class Print1_100 {

	public void Print1_100() {

	}

	public void func1() {
		int i = 1;
		System.out.println("使用while循环");
		while (i <= 100) {
			System.out.println(i);
			i++;
		}
	}

	public void func2() {
		int i;
		System.out.println("使用for循环");
		for (i = 1; i <= 100; ++i) {
			System.out.println(i);
		}
	}

	public void func3() {
		int i = 1;
		System.out.println("使用do……while");
		do {
			System.out.println(i);
			i++;
		} while (i <= 100);
	}

	public void func4(int n) {
		if (n == 100) {
			System.out.println(n);
			return;
		} else {
			System.out.println(n);
			func4(n + 1);
		}
	}

	public void func5(final int num) {
		final Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			private int i = 0;

			@Override
			public void run() {
				if (i <= num) {
					System.out.println(i++);
				} else {
					timer.cancel();
				}
			}
		}, 0, 1);
	}

	public void func6_break(int num) {
		int i = 1;
		while (i <= 100) {
			if (i == num)
				break;
			System.out.println(i);
			i++;
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Print1_100 printEx = new Print1_100();
		printEx.func1();
		printEx.func2();
		printEx.func3();
		System.out.println("使用递归");
		printEx.func4(1);
		System.out.println("在47时break");
		printEx.func6_break(47);
		System.out.println("使用定时器");
		printEx.func5(100);

	}

}
